﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using Sebarf.Diagnostics.Interfaces;

#endregion

namespace Utils {
	/// <summary>
	/// is a <see cref="ProcessStep"/>
	/// converts the object in the source to the target type
	/// calls NextConvertedStep after process
	/// </summary>
	public abstract class ProcessStepConverter<TSource, TTarget> : ProcessStep<TSource> {
		#region Public Properties

		public new ProcessStep<TTarget> NextStep { get; set; }

		#endregion

		#region Public Methods

		public override Object Process(TSource toProcess) {
			Check.AssertException(base.NextStep == null, "provide the next step as ProcessStep<" + typeof(TTarget) + ">");
			if (NextStep == null) {
				return Convert(toProcess);
			}
			else {
				return NextStep.Process(Convert(toProcess));
			}
		}

		public override IProcessStep GetNextStep() {
			return NextStep;
		}

		#endregion

		#region Private Methods

		protected abstract TTarget Convert(TSource toProcess);

		#endregion
	}
}